﻿using System;

namespace CodeStash.Addin.Core
{
    [Serializable]
    public class LoginDetails
    {
        public LoginDetails()
        {

        }
        public string EmailAddress { get; set; }
        public string Password { get; set; }
        public string Token { get; set; }

        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(EmailAddress))
                throw new ArgumentNullException("EmailAddress");
            if (string.IsNullOrWhiteSpace(Token) && string.IsNullOrWhiteSpace(Password))
                throw new ApplicationException("You must specify the password or open id.");
        }

        public bool IsValid
        {
            get
            {
                bool isInvalid = string.IsNullOrWhiteSpace(EmailAddress) || (string.IsNullOrWhiteSpace(Token) && string.IsNullOrWhiteSpace(Password));
                return !isInvalid;
            }
        }
    }
}
